package 题目集.hash.字符串哈希;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * https://blog.csdn.net/a769973411/article/details/80400792
 * https://www.luogu.com.cn/problem/P8631
 * 回文哈希题
 */
public class 傻逼题意 {
    static int maxN = 100001;
    static char[] chars;
    static long[] base;
    static long p = 131;
    static long[] leftHash;
    static long[] rightHash;
    static int[] leftCount;
    static int[] rightCount;
    static int n;
    static Set<Long> lset = new HashSet<>();
    static Set<Long> rset = new HashSet<>();

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        sc.nextLine();
        chars = sc.nextLine().toCharArray();
        init();
        lset.add(leftHash[1]);
        leftCount[1] = 1;
        for (int r = 2; r <= n; r++) {
            for (int l = 1; l <= r; l++) {
                if ((r - l + 1) % 2 == 0) {
                    continue;
                }
                long lhash = lHash(l, r);
                long rhash = rHash(l, r);
                if (lhash == rhash && !lset.contains(lhash)) {
                    lset.add(lhash);
                    leftCount[r]++;
                }
            }
            leftCount[r] += leftCount[r - 1];
        }
        for (int l = n - 1; l > 0; l--) {
            for (int r = n; r > l; r--) {
                long v = lHash(l, r);
                if (!lset.contains(v)&&!rset.contains(v)) {
                    rightCount[l]++;
                    rset.add(v);
                }
            }
            rightCount[l] += rightCount[l + 1];
        }
        int res=0;
        for (int i = 1; i <= n; i++) {
            res=Math.max(res,leftCount[i]*rightCount[i+1]);
        }
        System.out.println(res);
    }

    private static void init() {
        leftHash = new long[n + 2];
        rightHash = new long[n + 2];
        leftCount = new int[n + 2];
        rightCount = new int[n + 2];
        base = new long[n + 1];
        base[0] = 1;
        for (int i = 1; i < base.length; i++) {
            base[i] = base[i - 1] * p;
        }
        for (int i = 1; i <= n; i++) {
            leftHash[i] = leftHash[i - 1] * p + chars[i - 1];
        }
        for (int i = n; i > 0; i--) {
            rightHash[i] = rightHash[i + 1] * p + chars[i - 1];
        }
    }

    public static long lHash(int l, int r) {
        return leftHash[r] - leftHash[l - 1] * base[r - l + 1];
    }

    public static long rHash(int l, int r) {
        return rightHash[l] - rightHash[r + 1] * base[r - l + 1];
    }

}
